﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BMproductions.Media.MediaPlayer.WMPPlus.Properties;
using System.Windows.Forms.Design;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Drawing.Design;
using System.Collections;

namespace BMproductions.Media.MediaPlayer.WMPPlus {
	public partial class TagEditorForm: Form {
		private PictureBox[] stars;

		public TagEditorForm() {
			InitializeComponent();
			
			stars = new PictureBox[] { starRating1, starRating25, starRating50, starRating75, starRating99 };

			//IPropertyValueUIService uiService = (IPropertyValueUIService)vstAttributes.Site.GetService(typeof(IPropertyValueUIService));
			//if (uiService != null)
			//    uiService.AddPropertyValueUIHandler(new PropertyValueUIHandler(this.marginPropertyValueUIHandler));
			vstAttributes.Site = new EditableValue();
			vstAttributes.SelectedObject = this;
		}

		private void starRating_MouseEnter(object sender, EventArgs e) {
			var picture = (PictureBox)sender;
			foreach (var star in stars) {
				star.Image = star.Left <= picture.Left ? Resources.Star2 : Resources.Star4;
			}
		}

		private void starRating_MouseLeave(object sender, EventArgs e) {
			foreach (var star in stars) {
				star.Image = Resources.Star1;
			}
		}

	}

	public class EditableValue: ISite, IPropertyValueUIService {
		public IComponent Component { get { return null; } }
		public IContainer Container { get { return null; } }
		public bool DesignMode { get { return false; } }
		public string Name { get; set; }

		public object GetService(Type serviceType) {
			if (serviceType == typeof(IPropertyValueUIService))
				return this;
			return null;
		}

		public void AddPropertyValueUIHandler(PropertyValueUIHandler newHandler) { }
		public void NotifyPropertyValueUIItemsChanged() { }
		public event EventHandler PropertyUIValueItemsChanged;
		public void RemovePropertyValueUIHandler(PropertyValueUIHandler newHandler) { }

		public PropertyValueUIItem[] GetPropertyUIValueItems(ITypeDescriptorContext context, PropertyDescriptor propDesc) {
			if (propDesc.IsReadOnly || !propDesc.IsLocalizable)
				return null;
			return new PropertyValueUIItem[] {
				new PropertyValueUIItem(Resources.Pen.ToBitmap(), new PropertyValueUIItemInvokeHandler(this.marginInvoke), "Editable")
			};
		}

		private void marginInvoke(System.ComponentModel.ITypeDescriptorContext context, System.ComponentModel.PropertyDescriptor propDesc, PropertyValueUIItem item) {
		}

	}
}
